home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb-4.5 / dist / bfd / aout-target.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-17  |  10.5 KB  |  350 lines

  1. /* Define a target vector and some small routines for a variant of a.out.
  2.    Copyright (C) 1990-1991 Free Software Foundation, Inc.
  3.  
  4. This file is part of BFD, the Binary File Descriptor library.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "aout/aout64.h"
  21. #include "aout/stab_gnu.h"
  22. #include "aout/ar.h"
  23. /*#include "libaout.h"*/
  24.  
  25. /* Set parameters about this a.out file that are machine-dependent.
  26.    This routine is called from some_aout_object_p just before it returns.  */
  27. static bfd_target *
  28. DEFUN(MY(callback),(abfd),
  29.       bfd *abfd)
  30. {
  31.   struct internal_exec *execp = exec_hdr (abfd);
  32.   
  33. /* Calculate the file positions of the parts of a newly read aout header */
  34.   obj_textsec (abfd)->_raw_size = N_TXTSIZE(*execp);
  35.  
  36.   /* The virtual memory addresses of the sections */
  37.   obj_textsec (abfd)->vma = N_TXTADDR(*execp);
  38.   obj_datasec (abfd)->vma = N_DATADDR(*execp);
  39.   obj_bsssec  (abfd)->vma = N_BSSADDR(*execp);
  40.  
  41.   /* The file offsets of the sections */
  42.   obj_textsec (abfd)->filepos = N_TXTOFF (*execp);
  43.   obj_datasec (abfd)->filepos = N_DATOFF (*execp);
  44.  
  45.   /* The file offsets of the relocation info */
  46.   obj_textsec (abfd)->rel_filepos = N_TRELOFF(*execp);
  47.   obj_datasec (abfd)->rel_filepos = N_DRELOFF(*execp);
  48.  
  49.   /* The file offsets of the string table and symbol table.  */
  50.   obj_sym_filepos (abfd) = N_SYMOFF (*execp);
  51.   obj_str_filepos (abfd) = N_STROFF (*execp);
  52.   
  53.   /* Determine the architecture and machine type of the object file.  */
  54. #ifdef SET_ARCH_MACH
  55.   SET_ARCH_MACH(abfd, *execp);
  56. #else
  57.   bfd_default_set_arch_mach(abfd, DEFAULT_ARCH, 0);
  58. #endif
  59.  
  60.   adata(abfd).page_size = PAGE_SIZE;
  61. #ifdef SEGMENT_SIZE
  62.   adata(abfd).segment_size = SEGMENT_SIZE;
  63. #else
  64.   adata(abfd).segment_size = PAGE_SIZE;
  65. #endif
  66.   adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
  67.  
  68.   return abfd->xvec;
  69. }
  70.  
  71. #ifndef MY_object_p
  72. /* Finish up the reading of an a.out file header */
  73.  
  74. static bfd_target *
  75. DEFUN(MY(object_p),(abfd),
  76.      bfd *abfd)
  77. {
  78.   struct external_exec exec_bytes;    /* Raw exec header from file */
  79.   struct internal_exec exec;        /* Cleaned-up exec header */
  80.   bfd_target *target;
  81.  
  82.   if (bfd_read ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd)
  83.       != EXEC_BYTES_SIZE) {
  84.     bfd_error = wrong_format;
  85.     return 0;
  86.   }
  87.  
  88.   exec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info);
  89.  
  90.   if (N_BADMAG (exec)) return 0;
  91.  
  92.   NAME(aout,swap_exec_header_in)(abfd, &exec_bytes, &exec);
  93.   target = NAME(aout,some_aout_object_p) (abfd, &exec, MY(callback));
  94.  
  95. #ifdef ENTRY_CAN_BE_ZERO
  96.   /* The NEWSOS3 entry-point is/was 0, which (amongst other lossage)
  97.    * means that it isn't obvious if EXEC_P should be set.
  98.    * All of the following must be true for an executable:
  99.    * There must be no relocations, the bfd can be neither an
  100.    * archive nor an archive element, and the file must be executable. */
  101.  
  102.   if (exec.a_trsize + exec.a_drsize == 0
  103.       && bfd_get_format(abfd) == bfd_object && abfd->my_archive == NULL)
  104.     {
  105.       struct stat buf;
  106. #ifndef S_IXUSR
  107. #define S_IXUSR 0100    /* Execute by owner.  */
  108. #endif
  109.       if (stat(abfd->filename, &buf) == 0 && (buf.st_mode & S_IXUSR))
  110.     abfd->flags |= EXEC_P;
  111.     }
  112. #endif /* ENTRY_CAN_BE_ZERO */
  113.  
  114.   return target;
  115. }
  116. #define MY_object_p MY(object_p)
  117. #endif
  118.  
  119.  
  120. #ifndef MY_mkobject
  121. static boolean
  122. DEFUN(MY(mkobject),(abfd),
  123.       bfd *abfd)
  124. {
  125.   if (NAME(aout,mkobject)(abfd) == false)
  126.     return false;
  127.   adata(abfd).page_size = PAGE_SIZE;
  128. #ifdef SEGMENT_SIZE
  129.   adata(abfd).segment_size = SEGMENT_SIZE;
  130. #else
  131.   adata(abfd).segment_size = PAGE_SIZE;
  132. #endif
  133.   adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
  134.   return true;
  135. }
  136. #define MY_mkobject MY(mkobject)
  137. #endif
  138.  
  139. /* Write an object file.
  140.    Section contents have already been written.  We write the
  141.    file header, symbols, and relocation.  */
  142.  
  143. #ifndef MY_write_object_contents
  144. static boolean
  145. DEFUN(MY(write_object_contents),(abfd),
  146.       bfd *abfd)
  147. {
  148.   bfd_size_type data_pad = 0;
  149.   struct external_exec exec_bytes;
  150.   struct internal_exec *execp = exec_hdr (abfd);
  151.  
  152. #if CHOOSE_RELOC_SIZE
  153.   CHOOSE_RELOC_SIZE(abfd);
  154. #else
  155.   obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
  156. #endif
  157.  
  158.   WRITE_HEADERS(abfd, execp);
  159.  
  160.   return true;
  161. }
  162. #define MY_write_object_contents MY(write_object_contents)
  163. #endif
  164.  
  165. /* We assume BFD generic archive files.  */
  166. #ifndef    MY_openr_next_archived_file
  167. #define    MY_openr_next_archived_file    bfd_generic_openr_next_archived_file
  168. #endif
  169. #ifndef    MY_generic_stat_arch_elt
  170. #define    MY_generic_stat_arch_elt    bfd_generic_stat_arch_elt
  171. #endif
  172. #ifndef    MY_slurp_armap
  173. #define    MY_slurp_armap            bfd_slurp_bsd_armap
  174. #endif
  175. #ifndef    MY_slurp_extended_name_table
  176. #define    MY_slurp_extended_name_table    bfd_true
  177. #endif
  178. #ifndef    MY_write_armap
  179. #define    MY_write_armap        bsd_write_armap
  180. #endif
  181. #ifndef    MY_truncate_arname
  182. #define    MY_truncate_arname        bfd_bsd_truncate_arname
  183. #endif
  184.  
  185. /* No core file defined here -- configure in trad-core.c separately.  */
  186. #ifndef    MY_core_file_failing_command
  187. #define    MY_core_file_failing_command _bfd_dummy_core_file_failing_command
  188. #endif
  189. #ifndef    MY_core_file_failing_signal
  190. #define    MY_core_file_failing_signal    _bfd_dummy_core_file_failing_signal
  191. #endif
  192. #ifndef    MY_core_file_matches_executable_p
  193. #define    MY_core_file_matches_executable_p    \
  194.                 _bfd_dummy_core_file_matches_executable_p
  195. #endif
  196. #ifndef    MY_core_file_p
  197. #define    MY_core_file_p        _bfd_dummy_target
  198. #endif
  199.  
  200. #ifndef MY_bfd_debug_info_start
  201. #define MY_bfd_debug_info_start        bfd_void
  202. #endif
  203. #ifndef MY_bfd_debug_info_end
  204. #define MY_bfd_debug_info_end        bfd_void
  205. #endif
  206. #ifndef MY_bfd_debug_info_accumulate
  207. #define MY_bfd_debug_info_accumulate    (PROTO(void,(*),(bfd*, struct sec *))) bfd_void
  208. #endif
  209.  
  210. #ifndef MY_core_file_failing_command
  211. #define MY_core_file_failing_command NAME(aout,core_file_failing_command)
  212. #endif
  213. #ifndef MY_core_file_failing_signal
  214. #define MY_core_file_failing_signal NAME(aout,core_file_failing_signal)
  215. #endif
  216. #ifndef MY_core_file_matches_executable_p
  217. #define MY_core_file_matches_executable_p NAME(aout,core_file_matches_executable_p)
  218. #endif
  219. #ifndef MY_slurp_armap
  220. #define MY_slurp_armap NAME(aout,slurp_armap)
  221. #endif
  222. #ifndef MY_slurp_extended_name_table
  223. #define MY_slurp_extended_name_table NAME(aout,slurp_extended_name_table)
  224. #endif
  225. #ifndef MY_truncate_arname
  226. #define MY_truncate_arname NAME(aout,truncate_arname)
  227. #endif
  228. #ifndef MY_write_armap
  229. #define MY_write_armap NAME(aout,write_armap)
  230. #endif
  231. #ifndef MY_close_and_cleanup
  232. #define MY_close_and_cleanup NAME(aout,close_and_cleanup)
  233. #endif
  234. #ifndef MY_set_section_contents
  235. #define MY_set_section_contents NAME(aout,set_section_contents)
  236. #endif
  237. #ifndef MY_get_section_contents
  238. #define MY_get_section_contents NAME(aout,get_section_contents)
  239. #endif
  240. #ifndef MY_new_section_hook
  241. #define MY_new_section_hook NAME(aout,new_section_hook)
  242. #endif
  243. #ifndef MY_get_symtab_upper_bound
  244. #define MY_get_symtab_upper_bound NAME(aout,get_symtab_upper_bound)
  245. #endif
  246. #ifndef MY_get_symtab
  247. #define MY_get_symtab NAME(aout,get_symtab)
  248. #endif
  249. #ifndef MY_get_reloc_upper_bound
  250. #define MY_get_reloc_upper_bound NAME(aout,get_reloc_upper_bound)
  251. #endif
  252. #ifndef MY_canonicalize_reloc
  253. #define MY_canonicalize_reloc NAME(aout,canonicalize_reloc)
  254. #endif
  255. #ifndef MY_make_empty_symbol
  256. #define MY_make_empty_symbol NAME(aout,make_empty_symbol)
  257. #endif
  258. #ifndef MY_print_symbol
  259. #define MY_print_symbol NAME(aout,print_symbol)
  260. #endif
  261. #ifndef MY_get_lineno
  262. #define MY_get_lineno NAME(aout,get_lineno)
  263. #endif
  264. #ifndef MY_set_arch_mach
  265. #define MY_set_arch_mach NAME(aout,set_arch_mach)
  266. #endif
  267. #ifndef MY_openr_next_archived_file
  268. #define MY_openr_next_archived_file NAME(aout,openr_next_archived_file)
  269. #endif
  270. #ifndef MY_find_nearest_line
  271. #define MY_find_nearest_line NAME(aout,find_nearest_line)
  272. #endif
  273. #ifndef MY_generic_stat_arch_elt
  274. #define MY_generic_stat_arch_elt NAME(aout,generic_stat_arch_elt)
  275. #endif
  276. #ifndef MY_sizeof_headers
  277. #define MY_sizeof_headers NAME(aout,sizeof_headers)
  278. #endif
  279. #ifndef MY_bfd_debug_info_start
  280. #define MY_bfd_debug_info_start NAME(aout,bfd_debug_info_start)
  281. #endif
  282. #ifndef MY_bfd_debug_info_end
  283. #define MY_bfd_debug_info_end NAME(aout,bfd_debug_info_end)
  284. #endif
  285. #ifndef MY_bfd_debug_info_accumulat
  286. #define MY_bfd_debug_info_accumulat NAME(aout,bfd_debug_info_accumulat)
  287. #endif
  288.  
  289. bfd_target MY(vec) =
  290. {
  291.   TARGETNAME,        /* name */
  292.   bfd_target_aout_flavour,
  293. #ifdef TARGET_IS_BIG_ENDIAN_P
  294.   true,                /* target byte order (big) */
  295.   true,                /* target headers byte order (big) */
  296. #else
  297.   false,            /* target byte order (little) */
  298.   false,            /* target headers byte order (little) */
  299. #endif
  300.   (HAS_RELOC | EXEC_P |        /* object flags */
  301.    HAS_LINENO | HAS_DEBUG |
  302.    HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
  303.   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
  304.   ' ',                /* ar_pad_char */
  305.   15,                /* ar_max_namelen */
  306.   1,                /* minimum alignment */
  307. #ifdef TARGET_IS_BIG_ENDIAN_P
  308.   _do_getb64, _do_putb64,    _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* data */
  309.   _do_getb64, _do_putb64,    _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */
  310. #else
  311.   _do_getl64, _do_putl64,    _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* data */
  312.   _do_getl64, _do_putl64,    _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* hdrs */
  313. #endif
  314.     {_bfd_dummy_target, MY_object_p, /* bfd_check_format */
  315.        bfd_generic_archive_p, MY_core_file_p},
  316.     {bfd_false, MY_mkobject,    /* bfd_set_format */
  317.        _bfd_generic_mkarchive, bfd_false},
  318.     {bfd_false, MY_write_object_contents, /* bfd_write_contents */
  319.        _bfd_write_archive_contents, bfd_false},
  320.  
  321.   MY_core_file_failing_command,
  322.   MY_core_file_failing_signal,
  323.   MY_core_file_matches_executable_p,
  324.   MY_slurp_armap,
  325.   MY_slurp_extended_name_table,
  326.   MY_truncate_arname,
  327.   MY_write_armap,
  328.   MY_close_and_cleanup,
  329.   MY_set_section_contents,
  330.   MY_get_section_contents,
  331.   MY_new_section_hook,
  332.   MY_get_symtab_upper_bound,
  333.   MY_get_symtab,
  334.   MY_get_reloc_upper_bound,
  335.   MY_canonicalize_reloc,
  336.   MY_make_empty_symbol,
  337.   MY_print_symbol,
  338.   MY_get_lineno,
  339.   MY_set_arch_mach,
  340.   MY_openr_next_archived_file,
  341.   MY_find_nearest_line,
  342.   MY_generic_stat_arch_elt,
  343.   MY_sizeof_headers,
  344.   MY_bfd_debug_info_start,
  345.   MY_bfd_debug_info_end,
  346.   MY_bfd_debug_info_accumulate,
  347.   bfd_generic_get_relocated_section_contents,
  348.   bfd_generic_relax_section
  349. };
  350.